package com.haier.nengyuan.myapplication;

import android.graphics.PointF;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.TextView;

import java.util.ArrayList;
/**
 * Created by wy on 2017/8/28.
 */

public class DayEnergyFragment01 extends BaseFragment {

    private ArrayList<PointF> mPointArrayList = new ArrayList<>();
    private TextView mTvDayEarningTotal;
    private FrameLayout frameLayout;
    private float mDayEarningTotal;
    private long time = System.currentTimeMillis();
    private String mStrHour;
    private String mStrMonth;
    private String mStrDay;
    private float dayTal;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_day_energy01, container, false);
        frameLayout = (FrameLayout) view.findViewById(R.id.frame_layout);
        mTvDayEarningTotal = (TextView) view.findViewById(R.id.tv_day_earning_total);
        return view;
    }

   /* @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mStrHour = MyDateUtil.changeH(System.currentTimeMillis());
        mStrDay = MyDateUtil.changeD(System.currentTimeMillis());
        Integer day = Integer.valueOf(mStrDay);
        mStrMonth = MyDateUtil.changeM(System.currentTimeMillis());
        WindowManager wm = getActivity().getWindowManager();

        int width = (wm.getDefaultDisplay().getWidth() - 120) / 13;
        Log.e("---", "onViewCreated: " + mStrMonth + ":" + mStrDay + ":" + mStrHour + "day:" + day);
        int mIntHour1 = (int) (Integer.parseInt(mStrHour) / 2);
        if (mStrMonth.equals("09")) {
            for (int i = 0; i <= mIntHour1; i++) {
                dayTal += points4[i][1];
                mPointArrayList.add(new PointF(points4[i][0], (float) (Float.valueOf(Variable.nineDayEnergy[day - 1]) * (points4[i][1] / 31.97))));
                float y = mPointArrayList.get(i).y;
                mDayEarningTotal = mDayEarningTotal + y;
                View view1 = new View(getActivity());
                FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(width - 10, (int) (y * 100));//日累计发电量柱状图宽高
                layoutParams.gravity = Gravity.BOTTOM;
                if (i == 0) {
                    layoutParams.setMarginStart((width) * i + 60);

                } else {
                    layoutParams.setMarginStart((width) * i + 60 + 3 * i);

                }
                view1.setLayoutParams(layoutParams);
                view1.setBackgroundColor(0xffffffff);

                frameLayout.addView(view1);
            }
            String s = ((float) (Math.round(Float.valueOf(Variable.nineDayEnergy[day - 1]) * (dayTal / 31.97) * 100)) / 100) + "";
            mTvDayEarningTotal.setText(s);
            Variable.dayEle = s;
        }
        if (mStrMonth.equals("10")) {
            for (int i = 0; i <= mIntHour1; i++) {
                dayTal += points4[i][1];
                mPointArrayList.add(new PointF(points4[i][0], (float) (Float.valueOf(Variable.tenDayEnergy[day - 1]) * (points4[i][1] / 31.97))));
                float y = mPointArrayList.get(i).y;
                mDayEarningTotal = mDayEarningTotal + y;
                View view1 = new View(getActivity());
                FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(width - 10, (int) (y * 100));//日累计发电量柱状图宽高
                layoutParams.gravity = Gravity.BOTTOM;
                if (i == 0) {
                    layoutParams.setMarginStart((width) * i + 60);

                } else {
                    layoutParams.setMarginStart((width) * i + 60 + 3 * i);

                }
                view1.setLayoutParams(layoutParams);
                view1.setBackgroundColor(0xffffffff);

                frameLayout.addView(view1);
            }
            String s = ((float) (Math.round(Float.valueOf(Variable.tenDayEnergy[day - 1]) * (dayTal / 31.97) * 100)) / 100) + "";
            mTvDayEarningTotal.setText(s);
            Variable.dayEle = s;

        }
        if (mStrMonth.equals("11")) {
            for (int i = 0; i <= mIntHour1; i++) {
                dayTal += points4[i][1];
                mPointArrayList.add(new PointF(points4[i][0], (float) (Float.valueOf(Variable.eleEnergy[day - 1]) * (points4[i][1] / 31.97))));
                float y = mPointArrayList.get(i).y;
                mDayEarningTotal = mDayEarningTotal + y;
                View view1 = new View(getActivity());
                FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(width - 10, (int) (y * 100));//日累计发电量柱状图宽高
                layoutParams.gravity = Gravity.BOTTOM;
                if (i == 0) {
                    layoutParams.setMarginStart((width) * i + 60);

                } else {
                    layoutParams.setMarginStart((width) * i + 60 + 3 * i);

                }
                view1.setLayoutParams(layoutParams);
                view1.setBackgroundColor(0xffffffff);

                frameLayout.addView(view1);
            }
            String s = ((float) (Math.round(Float.valueOf(Variable.eleEnergy[day - 1]) * (dayTal / 31.97) * 100)) / 100) + "";
            mTvDayEarningTotal.setText(s);
            Variable.dayEle = s;

        }
        if (mStrMonth.equals("12")) {
            for (int i = 0; i <= mIntHour1; i++) {
                dayTal += points4[i][1];
                mPointArrayList.add(new PointF(points4[i][0], (float) (Float.valueOf(Variable.decemberEnergy[day - 1]) * (points4[i][1] / 31.97))));
                float y = mPointArrayList.get(i).y;
                mDayEarningTotal = mDayEarningTotal + y;
                View view1 = new View(getActivity());
                FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(width - 10, (int) (y * 100));//日累计发电量柱状图宽高
                layoutParams.gravity = Gravity.BOTTOM;
                if (i == 0) {
                    layoutParams.setMarginStart((width) * i + 60);

                } else {
                    layoutParams.setMarginStart((width) * i + 60 + 3 * i);

                }
                view1.setLayoutParams(layoutParams);
                view1.setBackgroundColor(0xffffffff);

                frameLayout.addView(view1);
            }
            String s = ((float) (Math.round(Float.valueOf(Variable.decemberEnergy[day - 1]) * (dayTal / 31.97) * 100)) / 100) + "";
            mTvDayEarningTotal.setText(s);
            Variable.dayEle = s;

        }
             *//*总发电量*//*

    }*/

    private float mDataTotal;
    private float[] dayEnergy;
    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
    @Override
    public void onResume() {
        super.onResume();

        mDataTotal = 0;
        frameLayout.removeAllViews();

        long time = System.currentTimeMillis();
        int mMonth = Integer.parseInt(MyDateUtil.changeM(time));
        int mDay = Integer.parseInt(MyDateUtil.changeD(time));
        int mIntHour = Integer.parseInt(MyDateUtil.changeH(time)) / 2;
        if (mMonth == 9) {
            dayEnergy = VirtualData.nineDayEnergy;
        } else if (mMonth == 10) {
            dayEnergy = VirtualData.tenDayEnergy;
        } else if (mMonth == 11) {
            dayEnergy = VirtualData.eleEnergy;
        }else if (mMonth==12){
            dayEnergy=VirtualData.decemberEnergy;
        }else if (mMonth==1){
            dayEnergy=VirtualData.oneEnergy;
        }

        WindowManager wm = getActivity().getWindowManager();
//        int width = (wm.getDefaultDisplay().getWidth() - 160) / 13;
        int width = (wm.getDefaultDisplay().getWidth() - 120) / 13;
        for (int i = 0; i <= mIntHour; i++) {
            float y = (VirtualData.pointsDay[i][1] / VirtualData.mdataDay) * dayEnergy[mDay - 1];
            mDataTotal += y;

            View view1 = new View(getActivity());
//            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(width - 20, (int) (y * 76));
//            layoutParams.gravity = Gravity.BOTTOM;
//            layoutParams.setMarginStart((width) * i + 60 + 10);
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(width - 10, (int) (y * 100));//日累计发电量柱状图宽高
            layoutParams.gravity = Gravity.BOTTOM;
            if (i == 0) {
                layoutParams.setMarginStart((width) * i + 60);

            } else {
                layoutParams.setMarginStart((width) * i + 60 + 3 * i);

            }

            view1.setLayoutParams(layoutParams);
            view1.setBackgroundColor(0xffffffff);

            frameLayout.addView(view1);
        }

        mTvDayEarningTotal.setText((Math.round(mDataTotal * 100f)) / 100f + "");
    }
    @Override
    public int setRootView() {
        return 0;
    }

    @Override
    public void initViews() {


    }

}
